/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.chipchip.database;

import com.chipchip.database.tables.DTItem;
import com.chipchip.database.tables.DTMap;
import com.chipchip.database.tables.DTMapResult;
import com.chipchip.database.tables.DTObstacle;
import com.chipchip.database.tables.DTUser;
import com.chipchip.database.tables.DTUserMap;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.data.mongodb.core.MongoOperations;

/**
 *
 * @author Tri
 */
public class DBManager {
    private static DBManager instance = null;
    
    ApplicationContext m_context;
    MongoOperations m_mongoOperations;
    
    private DBManager() {
       m_context = new AnnotationConfigApplicationContext(DBConfig.class);
//        m_context = new GenericXmlApplicationContext("SpringConfig.xml");
        m_mongoOperations = (MongoOperations)m_context.getBean("mongoTemplate");
    }
    
    public static DBManager sharedInstance() {
        if(instance == null) {
            instance = new DBManager();
        }
        return instance;
    }
    
    public static void destroyInstance() {
        instance = null;
    }
    
    public MongoOperations mongoOperations() {
        return this.m_mongoOperations;
    }
    
    public DTItem itemTable() {
        return DTItem.sharedInstance();
    }
    
    public DTMap mapTable() {
        return DTMap.sharedInstance();
    }
    
    public DTMapResult mapResultTable() {
        return DTMapResult.sharedInstance();
    }
    
    public DTObstacle obstacleTable() {
        return DTObstacle.sharedInstance();
    }
    
    public DTUser userTable() {
        return DTUser.sharedInstance();
    }
    
    public DTUserMap userMapTable() {
        return DTUserMap.sharedInstance();
    }
}
